package com.raos.example.web;

import com.raos.example.service.ExportService;
import com.raos.example.service.ImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 导出控制器
 *
 * @author raos
 * @email 991207823@qq.com
 * @date 2023-08-26 9:57
 */
@RestController
public class EmployeeController {

    @Resource
    private ExportService exportService;
    @Autowired
    private ImportService importService;

    //方案一：查全表，写入一个sheet
    @GetMapping("export1")
    public void exportExcel1(HttpServletResponse response) throws IOException {
        exportService.exportExcel1(response);
    }

    //方案二：查全部，写入多个sheet
    @GetMapping("export2")
    public void exportExcel2(HttpServletResponse response) throws IOException {
        exportService.exportExcel2(response);
    }

    //方案三：分页查询，每页数据写入每个sheet
    @GetMapping("export3")
    public void exportExcel3(HttpServletResponse response) throws IOException {
        exportService.exportExcel3(response);
    }

    //方案四：多线程分页查询，每页数据写入多个sheet
    @GetMapping("export4")
    public void exportExcel4(HttpServletResponse response) throws IOException {
        exportService.exportExcel4(response);
    }

    @PostMapping("import")
    public void importExcel(MultipartFile file) throws IOException {
        // 方案1和方案2--单个sheet
        //importService.importExcel(file);
        // 方案3与方案4--数据拆分为多个sheet
        importService.importExcelAsync(file);
    }

}
